<template>
<view class="page__bd">
	<view class="daui-custom">
		<view class="daui-navbar ctui-navbar-wrap zzui-bg_primary" :style="[{height:CustomBar + 'px',paddingTop:StatusBar + 'px'}]">
			<view class="daui-navbar__icon">
				<view class="text-white text-xl" @click="openProductList">
					<text class="bui-searchcate-icon iconfontzz icon-manage_fill" style="color: rgb(255, 255, 255); font-size: 22px; font-weight: normal; margin: 0px;"></text>
					<view class="bui-searchcate-scale">分类</view>
				</view>
			</view>
			<view class="daui-navbar__text text-white">
				<view class="daui-searchbar zzui-searchbar">
					<view class="daui-searchbar__forum-area">
						<view class="daui-searchbar__hd">
							<image src="../../static/images/index/search.png" mode="scaleToFill"></image>
						</view>
						<view class="daui-searchbar__bd">
							<input confirm-type="search" class="daui-searchbar_input" v-model="keyword" placeholder="搜索商品/品牌" @click="openSearch" />
						</view>
					</view>
					<view class="daui-searchbar__btn-area" v-if="searchBtnShow">
						<text class="daui-btn" @tap="searchToGoods(keyword)">搜索</text>
					</view>
				</view>
			</view>
		</view>
	</view>
	
	<view class="ctui-banner-wrap" :style="scrollTop>CustomBar?'padding-top:50px':''">
		<view class="ctui-hotsearch zzui-bg_primary">
			<view class="ctui-hot-label">热搜</view>
			<view v-for="(item,index) in hotsearchList" :key="index" class="ctui-hot-tag" @tap="searchToGoods(item.name)">
				{{item.name}}
			</view>
		</view>
		<view class="ctui-banner-box">
			<view class="ctui-banner-bg zzui-bg_primary">
				<view class="ctui-primary-bg zzui-bg_primary ctui-route-left"></view>
				<view class="ctui-primary-bg zzui-bg_primary ctui-route-right"></view>
			</view>
			<!-- 图片轮播 -->
			<view class="swiper-box">
				<swiper class="daui-swiper square-dot" :indicator-dots="true" circular="true" autoplay="true" interval="5000" duration="500">
					<swiper-item v-for="(item,index) in slideList" :key="index" @tap="openPageLink(item.page_flag, item.page_data, item.page_extra)">
						<image :src="item.picurl_show" mode="scaleToFill"></image>
					</swiper-item>
				</swiper>
			</view>
		</view>
	</view>
	
	<!-- 首屏图标导航 -->
	<view class="daui-card daui-card_mellow home-icon-wrap" v-if="navigationList.length > 0">
		<view class="daui-card__bd">
			<view class="daui-grid col-4 home-icon">
				<view hover-class="none" class="daui-grid__item" v-for="(item,index) in navigationList" :key="index" @tap="openPageLink(item.page_flag, item.page_data)">
					<view class="daui-grid_icon">
						<image :src="item.picurl_show" mode="aspectFill"></image>
						<view class="cu-tag badge" v-if="item.badge">
							<block v-if="item.badge!=1">{{item.badge>99?'99+':item.badge}}</block>
						</view>
					</view>
					<text class="daui-grid_text">{{item.name}}</text>
				</view>
			</view>
		</view>
	</view>
	
	<!-- 公告栏 -->
	<view class="home-notice-wrap">
		<view class="daui-cell bg-white">
			<view class="daui-cell__hd">
				<text class="iconfontzz icon-notification"></text>
			</view>
			<view class="daui-cell__bd">
				<swiper circular="true" :indicator-dots="false" vertical="true" :autoplay="false" interval="50000" duration="5000">
					<swiper-item v-for="(item,index) in announceList" :key="index">
						<view class="swiper-item" @tap="openPageLink(item.page_flag, item.page_data, item.page_extra)">
							<text class="swiper-em"></text><text class="mr-xs" v-if="item.tag">{{item.tag}}</text> {{item.title}}
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
	</view>
	
	<!-- 推荐文章 -->
	<view class="home-article-wrap" v-if="newArticleList.length > 0">
		<view class="daui-cell bg-white">
			<view class="daui-cell__hd">
				<image :src="danceData.webURL+'/appres/home/new-icon.png'" mode="widthFix" @tap="openArticleList"></image>
			</view>
			<view class="daui-cell__bd">
				<swiper circular="true" :indicator-dots="false" vertical="true" autoplay="true" interval="5000" duration="500">
					<swiper-item v-for="(item,index) in newArticleList" :key="index">
						<view class="swiper-item" @tap="openArticleDetail(item.id)">
							<text class="swiper-em"></text><text class="mr-xs" v-if="item.cate_name
">[{{item.cate_name}}]</text> {{item.title}}
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
	</view>
	
	<block v-for="(item, index) in wapcustomList" :key="index">
		<view class="daui-media__banner margin-top-sm" v-if="item.kind_id == 1">
			<image :src="item.advert_picurl_show" mode="widthFix" @tap="openPageLink(item.advert_page_flag, item.advert_page_data, item.advert_page_extra)"></image>
		</view>
		<view class="daui-card zzui-wapcustom" v-if="item.kind_id == 2">
			<view class="daui-card__hd">
				<view class="daui-cell daui-cell_access">
					<view class="daui-cell__bd">
						{{item.name}}
					</view>
					<view class="daui-cell__ft" v-if="item.more_name" @tap="openPageLink(item.more_page_flag, item.more_page_data, item.page_extra)">{{item.more_name}}</view>
				</view>
			</view>
			<view class="daui-card__bd">
				<image :src="item.advert_picurl_show" mode="widthFix" @tap="openPageLink(item.advert_page_flag, item.advert_page_data)" v-if="item.picurl"></image>
				<block v-if="item.show_style == 'text'">
					<list-text :templateInfo="item" :psList="item.sourceList" @childByValue="childByValue"></list-text>
				</block>
				<block v-else-if="item.show_style == 'double'">
					<list-double :templateInfo="item" :psList="item.sourceList" :imgExhibitionHeight="imgExhibitionDoubleHeight" @childByValue="childByValue"></list-double>
				</block>
				<block v-else-if="item.show_style == 'pictxt'">
					<list-pictxt :templateInfo="item" :psList="item.sourceList" @childByValue="childByValue"></list-pictxt>
				</block>
				<block v-else-if="item.show_style == 'bigpic'">
					<list-bigpic :templateInfo="item" :psList="item.sourceList" @childByValue="childByValue"></list-bigpic>
				</block>
				<block v-else-if="item.show_style == 'slide'">
					<list-slide :templateInfo="item" :psList="item.sourceList" @childByValue="childByValue"></list-slide>
				</block>
				<block v-else-if="item.show_style == 'combination'">
					<list-combination :templateInfo="item" :psList="item.sourceList" @childByValue="childByValue"></list-combination>
				</block>
			</view>
		</view>
	</block>
	
	<view class="daui-card bui-wapcustom" v-if="index_exhibition_mode > 0">
		<view class="classify-hd">
			<view class="classify-liner">
				<text class="classify-title">热门推荐</text>
			</view>
		</view>
		<view v-if="index_exhibition_mode == 1">
			<block v-for="(item, index) in productList" :key="index">
				<view class="daui-media daui-media_appmsg daui-media_product bg-white" hover-class="hover" :hover-start-time="150" @tap="openProductDetail(item.pid)">
					<view class="daui-media__hd">
						<image :src="item.picurl_show" mode="scaleToFill" lazy-load="true" class="daui-media__thumb"></image>
					</view>
					<view class="daui-media__bd">
						<view class="daui-media__title">{{item.name}}</view>
						<view class="daui-media__work">{{item.subtitle}}</view>
						<view class="daui-media__tag" v-if="item.attrtag_num > 0">
							<view v-for="(itemTag, indexTag) in item.attrtag" class="daui-badge daui-badge-sm" :class="itemTag.color">
								{{itemTag.name}}
							</view>
						</view>
						<view class="margin-top-xs">
							<text class="text-price text-red text-xl">{{item.real_price}}</text>
							<text class="text-price text-gray text-del text-sm margin-left-xs">{{item.origin_price}}</text>
						</view>
						<view class="flex justify-between align-end">
							<view class="flex align-center flex-sub">
								<view class="text-gray text-sm flex-sub">已售{{item.sale_num}}</view>
							</view>
							<view class="padding-left-xl text-right">
								<button class="daui-btn bg-primary round shadow daui-btn_sm"><text class="icon-lightfill"> </text>立即购买</button>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view class="daui-doublelist" v-else-if="index_exhibition_mode == 2">
			<block v-for="(item, index) in productList" :key="index">
				<view class="daui-doublelist__item">
					<view class="daui-media daui-media_appmsg daui-media_product bg-white" hover-class="hover" :hover-start-time="150">
						<view class="cart-quickcheck" v-if="0">
							<evan-checkbox :custom="item.pid" v-model="item.isCart" primaryColor="#eb0909"></evan-checkbox>
						</view>
						<view class="daui-media__bd">
							<view class="daui-media__banner">
								<image :src="item.picurl_show" mode="scaleToFill" :style="{'height':imgExhibitionDoubleHeight+'px'}"></image>
							</view>
							<view class="daui-media__bd_content">
								<view class="daui-media__prodtitle" @click="openProductDetail(item.pid)">{{item.name}}</view>
								<view class="daui-media__work">{{item.subtitle}}</view>
								<view class="daui-flex bui-brand">
									<view class="daui-flex__item">
										品牌：{{item.brand_name}}
									</view>
									<view class="daui-flex__item">
										产地：{{item.originplace}}
									</view>
								</view>
								<view class="daui-media__tag" v-if="item.attrtag_num > 0">
									<view v-for="(itemTag, indexTag) in item.attrtag" class="daui-badge daui-badge-sm" :class="itemTag.color">
										{{itemTag.name}}
									</view>
								</view>
								<view class="daui-flex margin-top-xs">
									<view class="daui-flex__item">
										<text class="text-red">{{item.real_price}}</text>
									</view>
									<view class="daui-flex__item text-right">
										<text class="text-gray">已售{{item.sale_num}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view class="waterfall-card" v-else-if="index_exhibition_mode == 3">
			<view class="waterfall-card_item">
				<block v-for="(item, index) in productList" :key="index">
					<view class="daui-media daui-media_appmsg daui-media_product shadow bg-white" hover-class="hover" :hover-start-time="150">
						<view class="cart-quickcheck">
							<evan-checkbox :custom="item.pid" v-model="item.isCart" primaryColor="#eb0909" :key="checkboxTimer"></evan-checkbox>
						</view>
						<view class="daui-media__bd">
							<view class="daui-media__banner">
								<image :src="item.picurl_show" mode="widthFix"></image>
							</view>
							<view class="waterfall-card_content">
								<view class="daui-media__title" @click="openProductDetail(item.pid)">{{item.name}}</view>
								<view class="daui-media__work">{{item.subtitle}}</view>
								<view class="daui-media__tag" v-if="item.attrtag_num > 0">
									<view v-for="(itemTag, indexTag) in item.attrtag" class="daui-badge daui-badge-sm" :class="itemTag.color">
										{{itemTag.name}}
									</view>
								</view>
								<view class="daui-flex">
									<view class="daui-flex__item">
										<text class="text-red">{{item.real_price}}</text>
									</view>
									<view class="daui-flex__item text-right">
										<text class="text-gray">已售{{item.sale_num}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view class="waterfall-card_item">
				<block v-for="(item, index) in productList2" :key="index">
					<view class="daui-media daui-media_appmsg daui-media_product shadow bg-white" hover-class="hover" :hover-start-time="150">
						<view class="cart-quickcheck">
							<evan-checkbox :custom="item.pid" v-model="item.isCart" primaryColor="#eb0909" :key="checkboxTimer"></evan-checkbox>
						</view>
						<view class="daui-media__bd">
							<view class="daui-media__banner">
								<image :src="item.picurl_show" mode="widthFix"></image>
							</view>
							<view class="waterfall-card_content">
								<view class="daui-media__title" @click="openProductDetail(item.pid)">{{item.name}}</view>
								<view class="daui-media__work">{{item.subtitle}}</view>
								<view class="daui-media__tag" v-if="item.attrtag_num > 0">
									<view v-for="(itemTag, indexTag) in item.attrtag" class="daui-badge daui-badge-sm" :class="itemTag.color">
										{{itemTag.name}}
									</view>
								</view>
								<view class="daui-flex">
									<view class="daui-flex__item">
										<text class="text-red">{{item.real_price}}</text>
									</view>
									<view class="daui-flex__item text-right">
										<text class="text-gray">已售{{item.sale_num}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
		</view>
		<view class="daui-load" :class="!loadding?'loading':'over'"><view class="daui-load-in"><view class="daui-nomore-text"></view></view></view>
	</view>
	
	<view class="daui-tabbar-height margin-top"></view>
	
	<!-- 浮动按钮 -->
	<view class="left-float" style="display: none;">
		<span @click="openFeedbackPublish">建议</span>
		<span @click="showKefuPopup" data-target="kefuModal">客服</span>
	</view>
	
	<uni-popup ref="versionPopup">
		<view class="daui-dialog padding-xl version-popup">
			<view class="daui-dialog__hd">
				发现新版本 {{versionInfo.version_name}}
			</view>
			<view class="daui-dialog__bd">
				{{versionInfo.content}}
			</view>
			<view class="daui-flex align-center">
				<view class="daui-flex__item padding-xs">
					<button class="daui-btn bg-grey block round" @click="hideVersionPopup">暂不升级</button>
				</view>
				<view class="daui-flex__item padding-xs">
					<button class="daui-btn bg-red block round" @click="startUpdateVersion">立即升级</button>
				</view>
			</view>
			<view class="daui-dialog-buttons">
				<view class="daui-dialog-button" @click="hideVersionPopup">
					<text class="iconfontzz icon-cha"></text>
				</view>
			</view>
		</view>
	</uni-popup>
	
	<!-- 登录弹窗 -->
	<uni-popup ref="loginPopup">
		<view class="daui-dialog">
			<view class="daui-dialog__bd daui-dialog__bd-padding text-center">
				欢迎关注{{configInfo.site_title}}，登录获取更多优惠！
			</view>
			<view class="daui-buttonbar btn-group">
				<button class="daui-btn daui-btn_default round shadow" @click="hideLoginPopup">取消</button>
				<button class="daui-btn zzui-btn_primary round shadow" @click="openLogin">登录</button>
			</view>
			<view class="daui-dialog-close">
				<text class="iconfontzz icon-roundclose" @click="hideLoginPopup"></text>
			</view>
		</view>
	</uni-popup>
	
	<!-- 分享弹窗 -->
	<uni-popup ref="sharePopup" type="bottom">
		<share-btn :sharedataTemp="sharedata"></share-btn>
	</uni-popup>
	
	<!--toast提示-->
	<daui-toast ref="toast"></daui-toast>
</view>
</template>

<script>
import uniPopup from "../../components/uni-popup/uni-popup.vue"
import danceuiTool from '../../utils/danceuiTool.js';
import numberTool from '../../utils/numberTool';
import listText from "../../components/list-text/list-text.vue";
import listDouble from "../../components/list-double/list-double.vue";
import listBigpic from "../../components/list-bigpic/list-bigpic.vue";
import listPictxt from "../../components/list-pictxt/list-pictxt.vue";
import http from "../../server/api-index.js";
var _self;
export default {
	components:{
		uniPopup,
		listText,
		listDouble,
		listBigpic,
		listPictxt
	},
	data() {
		return {
			StatusBar: this.StatusBar, //导航栏高度
			CustomBar: this.CustomBar, //状态栏高度
			danceData: this.danceData, //配置数据
			configInfo: {}, //配置数据
			shareInfo: {}, //分享数据
			sharedata: {},
			scrollTop: 0,
			windowWidth: this.windowWidth,
			keyword: '',
			searchBtnShow: false,
			pixelRatio: 1,
			TabCur: 0,
			newestQuotation: {},
			modalName: null,
			configInfo: {
				index_title: '',
				index_subtitle: ''
			},
			hotsearchList: [],
			slideList: [],
			index_swiper_ratio: 0,
			indexSwiperHeight: 0,
			navigationList: [],
			announceList: [],
			newArticleList: [],
			wapcustomList: [],
			categoryList: [],
			list_param:{
				p:1
			},
			nowPage:1,
			loadding: false,
			pullUpOn: true,
			index_exhibition_mode: 0,
			imgExhibitionDoubleHeight: 0,
			productList: [],
			productList2: [],
			checkboxTimer: 0,
			shid: 0,
			site_cart_buy_num: 0,
			cartBuyNum: 0,
			cartTotalPrice: 0,
			cartList: [],
			version: '',
			wgtversion: '',
			platform: '',
			versionInfo: {},
			current: 0,
		};
	},
	onLoad() {
		//console.log('=====index,onLoad');
		console.log('danceData:', this.danceData); //检测小程序是否支持
		_self = this;
		uni.getSystemInfo({
			success: function(res) {
				_self.platform = res.platform;
			}
		})
		//#ifdef APP-PLUS
		//应用版本号
		console.log('plus.runtime:', plus.runtime);
		_self.version = plus.runtime.version;
		//应用资源版本号
		plus.runtime.getProperty(plus.runtime.appid,function(inf){
			console.log('plus,inf:', inf);
			//danceuiTool.showToast('inf:'+JSON.stringify(inf));
			_self.wgtversion = inf.version;
			_self.checkVersion();
		});
		//#endif
		//#ifdef MP-ALIPAY
		uni.getSystemInfo({
			success: function (res) {
				if(res.pixelRatio>1){
					//正常这里给2就行，如果pixelRatio=3性能会降低一点
					//_self.pixelRatio =res.pixelRatio;
					_self.pixelRatio =2;
				}
			}
		});
		//#endif
		this.getLocation();
	},
	onShow(options){
		//console.log('=====index,onShow');
		this.getData();
	},
	onPullDownRefresh() {
		console.log('=====上拉刷新refresh');
		this.list_param = {...this.list_param,p:1}
		this.getData();
		setTimeout(() => {
			uni.stopPullDownRefresh()
		}, 200);
	},
	onPageScroll(e) {
		this.scrollTop = e.scrollTop;
	},
	async onReachBottom() {
		console.log('=====拉到底部onReachBottom');
		if (!this.pullUpOn) return;
		this.loadding = true;
		const token = uni.getStorageSync('token');
		let headers = {"Authorization":"Bearer "+token};
		this.list_param = {...this.list_param,p:++this.nowPage}
		let ret = await http.index(this.$refs.toast, this.list_param, headers);
		var retData = ret.data;
		if(retData.productList){
			if(this.index_exhibition_mode == 1){
				this.productList = [...this.productList,...retData.productList];
			}else if(this.index_exhibition_mode == 2){
				this.productList = [...this.productList,...retData.productList];
				this.productList2 = [...this.productList2,...retData.productList2];
			}
			this.nowPage = this.nowPage + 1;
		}else{
			this.loadding = false;
			this.pullUpOn = false;
		}
	},
	computed: {
		barStyleShow() {
			//console.log('=====style')
			var StatusBar = this.StatusBar;
			var CustomBar = this.CustomBar;
			//var style = `height:${CustomBar}px;padding-top:${StatusBar}px`;
			var style = `height:${CustomBar}px`;
			//console.log('=====style', style)
			return style
		},
		bannerStyleShow() {
			//console.log('=====style')
			var StatusBar = this.StatusBar;
			var CustomBar = this.CustomBar;
			var style = `padding-top:${StatusBar}px`;
			//console.log('=====style', style)
			return style
		}
	},
	methods: {
		async getData(){ //请求并获取数据
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			let ret = await http.index(this.$refs.toast, {}, headers, 1);
			console.log('index页面，获取到的数据：', ret);
			var retData = ret.data;
			this.configInfo = retData.configInfo;
			uni.setStorage({
				key: 'webname',
				data: retData.configInfo.site_title
			})
			uni.setStorage({
				key: 'is_thirdlogin',
				data: retData.configInfo.is_thirdlogin
			})
			uni.setNavigationBarTitle({
				title: retData.configInfo.site_title
			})
			this.slideList = retData.slideList;
			this.indexSwiperHeight = this.windowWidth * retData.index_swiper_ratio; //图片高度计算
			this.navigationList = retData.navigationList;
			this.announceList = retData.announceList;
			this.newArticleList = retData.newArticleList;
			this.hotsearchList = retData.hotsearchList;
			this.wapcustomList = retData.wapcustomList;
			this.categoryList = retData.categoryList;
			this.index_exhibition_mode = retData.index_exhibition_mode;
			if(retData.index_exhibition_mode == 1){
				this.productList = retData.productList;
			}else{
				this.productList = retData.productList;
				this.productList2 = retData.productList2;
			}
			this.imgExhibitionSingleHeight = this.windowWidth * retData.index_product_single_ratio; //图片高度计算
			this.imgExhibitionDoubleHeight = (this.windowWidth-50) * retData.index_product_double_ratio / 2; //图片高度计算
			console.log('窗口宽度:'+this.windowWidth+'图片轮播高度比率:'+retData.index_swiper_ratio+'图片轮播高度:'+this.indexSwiperHeight+';单栏展示高度比:'+this.imgExhibitionSingleHeight+';并排展示高度:'+this.imgExhibitionDoubleHeight);
			this.loadding = true;
			this.shareInfo = retData.shareInfo;
			this.shid = retData.shid;
			if(retData.moonInfo.uid > 0){
				//购物车角标
				if(retData.moonInfo.site_cart_buy_num > 0){
					uni.setTabBarBadge({
						index: 2,
						text: retData.moonInfo.site_cart_buy_num.toString()
					})
				}
				this.$refs.loginPopup.close();
			}else{
				this.$refs.loginPopup.open();
			}
			//todo h5调试
			//this.versionInfo = retData.versionInfo;
			//this.$refs.versionPopup.open();
		},
		async tabSelect(e) {
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			this.TabCur = e.currentTarget.dataset.index;
			let cid = e.currentTarget.dataset.cid;
			//this.verticalNavTop = (e.currentTarget.dataset.id - 1) * 50
			var param = {
				cid: cid
			}
			let ret = await http.index(this.$refs.toast, param, headers);
			console.log('index页面,获取到的数据：', ret);
			if(ret.code == 200){
				var retData = ret.data;
				this.productList = retData.productList;
				this.productList2 = retData.productList2;
				console.log('重新加载子组件evan-checkbox');
				this.checkboxTimer = new Date().getTime(); //重新加载子组件
			}
		},
		//清空购物车
		async doClearCart(id){
			var that = this;
			uni.showModal({
				title: '提示',
				content: '确认清空购物车吗？',
				success: function (res) {
					if (res.confirm) {
						that.doClearCartTwo();
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		},
		async doClearCartTwo(){
			const token = uni.getStorageSync('token');
			let headers = {"Authorization":"Bearer "+token};
			var param = {
				shid: this.shid
			};
			let ret = await http.doClearCart(this.$refs.toast, param, headers);
			console.log('请求数据：', ret);
			if(ret.code == 200){
				var retData = ret.data;
				this.$refs.shopcart.close();
				//更新商品列表(方式一)
				var tmpProductList = this.productList;
				for(var key in tmpProductList){
					tmpProductList[key].buy_num = retData.productList[key].buy_num;
					//var tmpProdInfo = tmpProductList[key];
					//tmpProdInfo.buy_num = retData.productList[key].buy_num;
					//this.$set(this.productList, key, tmpProdInfo);
				}
				this.productList = tmpProductList;
				console.log('this.productList:', this.productList);
				this.cartBuyNum = retData.cartBuyNum;
				this.timer = new Date().getTime(); //重新加载子组件
			}
		},
		onShare(){
			this.$refs.sharePopup.open();
		},
		// 根据关键词搜索商品
		async searchToGoods(keyword) {
			console.log('搜索的关键词是:', keyword);
			if(!keyword){
				danceuiTool.showToast(this.$refs.toast, '搜索关键词不能为空');
				return;
			}
			uni.navigateTo({
				url: '/pages/product/search?keyword='+keyword
			})
			// const token = uni.getStorageSync('token');
			// let headers = {"Authorization":"Bearer "+token};
			// var param = {
			// 	keyword: keyword
			// }
			// let ret = await http.searchDoSearch(this.$refs.toast, param, headers);
			// var retData = ret.data;
			// console.log('searchDoSeach,获取到的数据：', retData);
			// this.productList = retData.productList;
			// this.showGoods = true
		},
		//#ifdef APP-PLUS
		async checkVersion(){ //请求并获取数据
			let param = {
				version: this.version,
				wgtversion: this.wgtversion,
				platform: this.platform,
				page: 'index'
			}
			console.log('=====当前版本号version:', this.version);
			console.log('=====当前资源版本号version:', this.wgtversion);
			console.log('=====当前平台platform:', this.platform);
			let ret = await http.checkVersion(this.$refs.toast, param);
			console.log('checkVersion操作,获取到的数据:', ret);
			if(ret.code == 200){
				var retData = ret.data;
				//版本更新
				let storage_versionPopup = uni.getStorageSync('storage_versionPopup');
				console.log('storage_versionPopup:', storage_versionPopup);
				if(storage_versionPopup != 0){
					if(retData.versionInfo.id){
						console.log('===检测到版本有更新');
						this.versionInfo = retData.versionInfo;
						this.$refs.versionPopup.open();
					}
				}
			}
			//todo h5调试
			//this.versionInfo = retData.versionInfo;
			//this.$refs.versionPopup.open();
		},
		//#endif
		getLocation(){
			var that = this;
			uni.getLocation({
				type: 'wgs84',
				success: function(res){
					console.log('当前位置的经度：' + res.longitude);
					console.log('当前位置的纬度：' + res.latitude);
					//danceuiTool.showToast('当前位置的经度：' + res.longitude);
					that.getLocationTwo(res.longitude, res.latitude);
				}
			});
		},
		async getLocationTwo(longitude, latitude){
			//获取用户登陆信息
			const token = uni.getStorageSync('token');
			if(token){
				let headers = {"Authorization":"Bearer "+token};
				var param = {
					longitude: longitude,
					latitude: latitude
				};
				let ret = await http.saveLocation(this.$refs.toast, param, headers);
				var retData = ret.data;
				console.log('saveLocation,获取到的数据：', retData);
			}
		},
		openPageLink(page_flag, page_data, page_extra){
			danceuiTool.dealLink(page_flag, page_data, page_extra);
		},
		childByValue: function(page_flag, page_data, page_extra) {
			danceuiTool.dealLink(page_flag, page_data, page_extra);
		},
		more: function(e) {
			let key = e.currentTarget.dataset.key || '';
			uni.navigateTo({
				url: '/pages/product/productList?searchKey=' + key
			});
		},
		hideLoginPopup(){
			this.$refs.loginPopup.close();
		},
		openProductDetail(pid){
			uni.navigateTo({
				url: '/pages/product/productDetail?pid='+pid
			});
		},
		openShopDetail(shid){
			uni.navigateTo({
				url: '/pages/shop/shopDetail?shid='+shid
			});
		},
		openSearch(shid){
			uni.navigateTo({
				url: '/pages/product/search'
			});
		},
		openFeedbackPublish(){
			uni.navigateTo({
				url: '/pagesA/feedback/publish'
			});
		},
		openArticleList(){
			uni.navigateTo({
				url: '/pagesA/article/articleList'
			});
		},
		openArticleDetail(arid){
			uni.navigateTo({
				url: '/pages/article/articleDetail?arid='+arid
			});
		},
		hideVersionPopup(){
			this.$refs.versionPopup.close();
			uni.setStorage({
				key: 'storage_versionPopup',
				data: 0
			})
		},
		startUpdateVersion(){
			console.log('=====立即升级,startUpdateVersion,platform:', this.platform);
			if(this.platform == 'android'){
				console.log('=====立即升级for android');
				this.startDownload();
			}else{
				console.log('=====立即升级for ios');
				this.startDownload();
				//plus.runtime.openURL(this.versionInfo.shichangurl);
			}
		},
		startDownload(){
			console.log('=====startDownload');
			if (this.versionInfo.is_shichang === 1) {
				//去应用市场更新
				plus.runtime.openURL(this.versionInfo.shichangurl);
				plus.runtime.restart();
			} else {
				// 开始下载
				// 创建下载任务
				console.log('=====createDownload');
				var dtask = plus.downloader.createDownload(this.versionInfo.wgturl, {
						filename: "_downloads/"
					},
					function(d, status) {
						console.log('d',d)
						console.log('status',status);
						// 下载完成
						if (status == 200) {
							plus.runtime.install(d.filename, {
								force: false
							}, function() {
								//进行重新启动;
								plus.runtime.restart();
							}, (e) => {
								uni.showToast({
									title: '安装升级包失败:' + JSON.stringify(e),
									icon: 'none'
								})
							});
						} else {
							uni.showToast("下载升级包失败，请手动去站点下载安装，错误码: " + status);
						}
				});
				let view = new plus.nativeObj.View("maskView", {
					backgroundColor: "rgba(255,255,255,.2)",
					left: ((plus.screen.resolutionWidth / 2) - 45) + "px",
					bottom: "80px",
					width: "90px",
					height: "30px"
				})
				view.drawText('开始下载', {}, {
					size: '14px',
					color: '#000000'
				});
				view.show()
				dtask.addEventListener("statechanged", (e) => {
					if (e && e.downloadedSize > 0) {
						let jindu = ((e.downloadedSize / e.totalSize) * 100).toFixed(2)
						view.reset();
						view.drawText(jindu + '%', {}, {
							size: '14px',
							color: '#000000'
						});
					}
				}, false);
				dtask.start();
			}
		}
	},
};
</script>

<style>
.daui-tabbar-height{height: 180rpx;}

.daui-bar{background-color:#e41f19;padding: 0 30rpx 0 20rpx;}
.daui-bar.fixed{
	min-height: 0px;
	/* #ifdef MP-WEIXIN */
	padding-right: 100px;
	/* #endif */
	/* #ifdef MP-QQ */
	padding-right: 100px;
	/* #endif */
	/* #ifdef MP-ALIPAY */
	padding-right: 150rpx;
	/* #endif */
	/*box-shadow: 0upx 0upx 0upx;*/
	box-shadow: 0rpx 0rpx 0rpx;
	padding-top: 40rpx;
}

.search-form{margin: 0;}
.bui-searchcate{font-size:24rpx;color:#fff;display:flex;align-items:center;justify-content:center;flex-direction:column;margin:0;margin-right:22rpx;flex-shrink:0}
.bui-searchcate-scale{transform:scale(0.7);line-height:24rpx}
.bui-searchcate-icon{line-height: 36rpx;margin-bottom: 0}

.ctui-banner-wrap{box-sizing: border-box;}
.ctui-hotsearch{color:#fff;font-size:24rpx;padding:24rpx 20rpx;box-sizing:border-box;position:relative;}
.ctui-hot-label{display: inline-block;margin-right: 20rpx;}
.ctui-hot-tag{display: inline-block;background-color:rgba(255,255,255,0.15);padding:10rpx 24rpx;border-radius:30rpx;line-height:24rpx;margin-right: 20rpx;}

.ctui-banner-box{position: relative;}
.ctui-banner-bg{display: flex;height: 180rpx;position: absolute;top: 0;width: 100%;}
.ctui-primary-bg{width:50%;display:inline-block;height:228rpx;border:1px solid transparent;position:relative;}
.ctui-route-left{transform:skewY(8deg)}
.ctui-route-right{transform:skewY(-8deg)}

/*搜索框*/
.zzui-searchbar{padding: 10rpx 30rpx}
.zzui-searchbar .daui-searchbar__hd{width: 36rpx;height:50rpx;margin-left:10rpx;margin-right: 8rpx;}
.zzui-searchbar .daui-searchbar__forum-area{background-color: #fff;height: 64rpx;line-height: 64rpx;}
.zzui-searchbar .daui-searchbar__hd image{width: 36rpx;height: 36rpx;}
.zzui-searchbar .daui-searchbar__bd .daui-searchbar_input{font-size: 26rpx;}
.zzui-searchbar .daui-searchbar__btn-area .daui-btn{color: #fff;}

.swiper-box{width:100%;padding:0 20rpx;box-sizing:border-box;}
.swiper-box .daui-swiper{border-radius:12rpx;overflow:hidden;transform:translateY(0)}

.home-icon-wrap{min-height:80rpx;z-index: 0;padding:10rpx 10rpx 0 10rpx;}
.daui-list.home-icon.grid,.daui-list.home-sort.grid{background-color: #ffffff;border-radius: 20rpx;}
.daui-list.home-sort.grid .daui-item{justify-content:center;align-items:center}
.daui-list.home-icon.grid .ellipseIcon{height:100upx;position:relative;display:flex;align-items:center;justify-content:center}
.daui-list.home-icon.grid .ellipseIcon view:first-child{position:relative;z-index:2;color:#FFFFFF;margin:auto;width:initial}
.daui-list.home-icon.grid .ellipseIcon image{position:absolute;width:90upx;height:90upx;z-index:9}
.daui-list.home-icon.grid .ellipseIcon .cu-tag.badge{z-index:2;border:1px solid #fff;box-sizing:content-box;box-shadow:6upx 6upx 8upx rgba(204,69,59,0.2)}
.daui-list.home-icon.grid .ellipseIcon .icon-ellipse{position:absolute;z-index:0;top:4upx;font-size:90upx;margin:auto;bottom:0}

.home-notice-wrap{min-height:60rpx;padding: 16rpx 20rpx 0 20rpx;z-index: 0;}
.home-notice-wrap .daui-cell{background-color: #FFF9EA;border: 1px solid #faebd2;color: #ffa106;border-radius: 20rpx;padding: 6rpx 20rpx;}
.home-notice-wrap .daui-cell__hd{width:46rpx;}
.home-notice-wrap .daui-cell__hd image{width: 100%;height: 100%;}
.home-notice-wrap .daui-cell__bd{}
.home-notice-wrap .daui-cell__hd .announce-img{width: 46rpx;}
.home-notice-wrap .daui-cell__hd .iconfontzz{font-size: 32rpx;}
.home-notice-wrap swiper{padding:0;height: 50rpx;line-height: 50rpx;}
.home-notice-wrap swiper .swiper-em{float: left;width: 4px;height: 4px;font-size: 0;margin: 11px 6px 5px 8px;background: #ed4040;display: none;}
.home-notice-wrap swiper .daui-badge{padding:0 10rpx;margin-right:15rpx;font-size: 28rpx;}

.home-article-wrap{min-height:80rpx;padding: 16rpx 20rpx 0 20rpx;z-index: 0;}
.home-article-wrap .daui-cell{color: #666666;border-radius: 20rpx;padding: 16rpx 20rpx;}
.home-article-wrap .daui-cell__hd{width:130rpx;height: 42rpx;margin-right: 20rpx;}
.home-article-wrap .daui-cell__hd image{width: 100%;height: 100%;}
.home-article-wrap .daui-cell__bd{}
.home-article-wrap .daui-cell__hd .announce-img{width: 46rpx;}
.home-article-wrap swiper{padding:0;height: 50rpx;line-height: 50rpx;font-size:26rpx;}
.home-article-wrap swiper .swiper-em{float: left;width: 4px;height: 4px;font-size: 0;margin: 11px 6px 5px 8px;background: #ed4040;display: none;}
.home-article-wrap swiper .daui-badge{height:40rpx;padding:0 10rpx;margin-right:15rpx}
</style>